package 背包问题01;

import java.util.Scanner;

public class Main {
    static int N = 1010;
    static int[] f = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        for (int i = 0; i < n; i++) {
            int v = in.nextInt();
            int w = in.nextInt();
            for (int j = m; j >= v; j--) {
                f[j] = Math.max(f[j], f[j - v] + w);
            }
        }
        System.out.println(f[m]);
    }
}
